<template>
  <Message/>
  <div ref="char1" id="char1"></div>
  <div ref="char2" id="char2"></div>
  <div id="container"></div>
</template>

<script>
import Message from '@v/DashBoard/Message.vue'
import * as echarts from 'echarts'
export default {
  name: 'DashBoard',
  data () {
    return {
      char1: null,
      char2: null,
      map: null
    }
  },
  methods: {
    ampLoader () {
      const map = new AMap.Map('container', {
        zoom: 12, // 级别
        center: [117.30984, 31.79502], // 中心点坐标
        viewMode: '3D', // 使用3D视图
        fillColor: '#fff', // 多边形填充颜色
        borderWeight: 2, // 线条宽度，默认为 1
        strokeColor: 'red' // 线条颜色
      })
      this.map = map
    },
    initChar () {
      const char1 = echarts.init(this.$refs.char1)
      // 绘制图表
      char1.setOption({
        title: {
          text: '最近48小时在线人数(整点为准)'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        legend: {
          data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false,
            data: ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期天']
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: 'Email',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: 'Union Ads',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: 'Video Ads',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            data: [150, 232, 201, 154, 190, 330, 410]
          },
          {
            name: 'Direct',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            data: [320, 332, 301, 334, 390, 330, 320]
          },
          {
            name: 'Search Engine',
            type: 'line',
            stack: 'Total',
            label: {
              show: true,
              position: 'top'
            },
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            data: [820, 932, 901, 934, 1290, 1330, 1320]
          }
        ]
      })
      this.char1 = char1
    },
    initChar2 () {
      const char2 = echarts.init(this.$refs.char2)
      // 绘制图表
      char2.setOption({
        legend: {
          top: 'bottom'
        },
        toolbox: {
          show: true,
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            restore: { show: true },
            saveAsImage: { show: true }
          }
        },
        series: [
          {
            name: 'Nightingale Chart',
            type: 'pie',
            radius: [50, 250],
            center: ['50%', '50%'],
            roseType: 'area',
            itemStyle: {
              borderRadius: 8
            },
            data: [
              { value: 40, name: 'rose 1' },
              { value: 38, name: 'rose 2' },
              { value: 32, name: 'rose 3' },
              { value: 30, name: 'rose 4' },
              { value: 28, name: 'rose 5' },
              { value: 26, name: 'rose 6' },
              { value: 22, name: 'rose 7' },
              { value: 18, name: 'rose 8' }
            ]
          }
        ]
      })
      this.char2 = char2
    }
  },
  mounted () {
    this.initChar()
    this.initChar2()
    this.ampLoader()
  },
  components: {
    Message
  }
}
</script>

<style lang="scss" scoped>
#char1{
  height: 500px;
  margin: 15px auto;
  background-color: azure;
}
#char2{
  height: 600px;
  margin: 15px auto;
  background-color: azure;
}
#container{
  // width: 1000px;
  height: 500px;
  margin: 0 auto;
  background-color: azure;
}
</style>
